package Ooday04;

public class Test {
    public static void main(String[] args) {
        Master master = new Master();
        Dog dog = new Dog("小黑", 1, "黑");
        Fish fish = new Fish("小灰", 1, "灰");
        Chick chick = new Chick("小红", 3, "红");
        master.feed(dog);
        master.feed(fish);
        master.feed(chick);


        //演示向上造型（多态）的第1点应用：
        //Animal o = new Animal();
        Animal[] animals = new Animal[5];
        animals[0] = new Dog("小黑", 2, "黑");
        animals[1] = new Dog("小白", 3, "白");
        animals[2] = new Fish("小金", 1, "金");
        animals[3] = new Chick("小灰", 2, "灰");
        for (int i = 0; i < animals.length; i++) {
            System.out.println(animals[i].name);
            animals[i].drink();
            animals[i].eat();

        if(animals[i] instanceof Dog){
            Dog dog1 = (Dog) animals[i];
            dog.lookHome();
        }
        if (animals[i] instanceof Chick){
            Chick chick1 = (Chick)animals[i];
            chick.layEggs();
        }
       if(animals[i] instanceof Swim){//适用于所有实现Swim接口的（会游泳的）
           Swim s = (Swim)animals[i];
           s.swim();
       }
        }
    }
}
